package com.community.web.master.controller;


import com.community.common.result.Result;
import com.community.model.entity.Store;
import com.community.web.master.domain.dto.*;
import com.community.web.master.domain.vo.PageResult;
import com.community.web.master.domain.vo.StoreGoodsVo;
import com.community.web.master.service.IStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李晶
 * @since 2024-07-02
 */
@RestController
@RequestMapping("/master/store")
@Slf4j
@Api(tags = "门店接口")
public class StoreController {
    @Autowired
    IStoreService iStoreService;
    @GetMapping("/pageQuery")
    @ApiOperation("门店分页查询")
    public Result<PageResult> pageQuery(PageStoreDto pageStoreDto){
        log.info("门店分页查询"+pageStoreDto);
        PageResult result = iStoreService.pageQuery(pageStoreDto);
        return Result.success(result);
    }

    @GetMapping("/pageQueryGoods")
    @ApiOperation("根据门店编号分页查询商品")
    public Result<PageResult> pageQueryGoods(PageStoreGoodsDto pageStoreGoodsDto){
        log.info("门店商品分页查询"+pageStoreGoodsDto);
        PageResult result =iStoreService.pageQueryGoods(pageStoreGoodsDto);
        return Result.success(result);
    }

    @PostMapping("/addGoods")
    @ApiOperation("添加商品")
    public Result addGoods(StoreGoodsDto storeGoodsDto){
        log.info("添加商品"+storeGoodsDto);
        iStoreService.addGoods(storeGoodsDto);
        return Result.success();
    }
    @DeleteMapping("/deleteGoods")
    @ApiOperation("删除商品")
    public Result deleteGoods(@RequestBody StoreGoodsDto storeGoodsDto){
        log.info("删除商品"+storeGoodsDto);
        iStoreService.deleteGoods(storeGoodsDto);
        return Result.success();
    }
    @PutMapping("/updateGoods")
    @ApiOperation("更新商品")
    public Result updateGoods(@RequestBody StoreGoodsDto storeGoodsDto){
        log.info("更新商品"+storeGoodsDto);
        iStoreService.updateGoods(storeGoodsDto);
        return Result.success();
    }

    @PostMapping("/add")
    @ApiOperation("新增门店")
    public Result addStore(StoreDto storeDto){
        log.info("新增门店"+storeDto);
        iStoreService.addStore(storeDto);
        return Result.success();
    }

    @PutMapping("/update")
    @ApiOperation("修改门店")
    public Result updateStore(@RequestBody StoreDto storeDto){
        log.info("修改门店"+storeDto);
        iStoreService.updateStore(storeDto);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除门店")
    public Result delete(@PathVariable Integer id){
        log.info("删除门店");
        iStoreService.deleteStore(id);
        return Result.success();
    }

}
